MediaWiki:Gadget-C helper tag.js

Une page de Wikipédia, l'encyclopédie libre.
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
//<nowiki>
C.tag = {
  dialog: null,
  config: {
    'modal-title': 'C helper - Ajouter/retirer des bandeaux de maintenance',
    'submit': 'Valider la requête',
    'c-tag-checkbox-class': 'c-tag-checkbox',
    'c-tag-radio-class': 'c-tag-radio',
    'notify-success': 'Les bandeaux ont bien été ajoutés.',
    'notify-no-reason': 'Vous n\'avez fait aucun changement.',
    'notify-not-a-page': 'Impossible de gérer les bandeaux d\'une page inexistante.',
    'notify-protected': 'Impossible de gérer les bandeaux de cette page, celle-ci est protégée.',
    'add-summary': 'Ajout de $1',
    'template-link-summary': '{{[[Modèle:$1|$1]]}}',
  },
  categories: [
  	{display:"Les plus utilisés", node:null}, //0
  	{display:"Admissibilité", node:null}, //1
  	{display:"Neutralité", node:null},    //2
  	{display:"Mise en forme", node:null}, //3
  	{display:"Sourçage", node:null}, //4
  ],
  /*
    {category:, display:'', template:'', help:'', reason:'', extra:''},
	Magic words :
		* $(page)
		* $(diff)
		* $(user)
		* $(day) $(month) $(year)
		* $(reason)
		* $(extra)
  */
  templates: [
	{category:3, display:'À catégoriser', template:'{{À catégoriser|date=$(month) $(year)}}', help:''},
	{category:3, display:'À dater', template:'{{À dater|date=$(month) $(year)}}', help:''},
	{category:3, display:'À déjargoniser', template:'{{À déjargoniser|date=$(month) $(year)}}', help:''},
	{category:3, display:'À délister', template:'{{À délister|date=$(month) $(year)}}', help:''},
	{category:3, display:'À désacadémiser', template:'{{À désacadémiser|date=$(month) $(year)}}', help:''},
	{category:3, display:'À désangliciser', template:'{{À désangliciser|date=$(month) $(year)}}', help:''},
	{category:3, display:'À fusionner', template:'{{À fusionner|$(extra)|date=$(month) $(year)}}', extra:'Liste des articles à fusionner, séparés par des « | » :', help:''},
	{category:3, display:'À illustrer', template:'{{À illustrer|date=$(month) $(year)}}', help:''},
	{category:3, display:'À recycler', template:'{{À recycler|date=$(month) $(year)}}', help:''},
	{category:0, display:'À sourcer', template:'{{À sourcer|date=$(month) $(year)}}', help:''},
	{category:3, display:'À TeXifier', template:'{{À TeXifier|date=$(month) $(year)}}', help:''},
	{category:4, display:'À vérifier', template:'{{À vérifier|date=$(month) $(year)}}', help:''},
	{category:0, display:'À wikifier', template:'{{À wikifier|date=$(month) $(year)}}', help:''},
	{category:0, display:'Admissibilité', template:'{{Admissibilité}}', help:'Attention, il faut à la suite de la pose de ce bandeau ouvrir manuellement la procédure de DDA. Suivez les explications qui apparaîtront sur le bandeau.'},
	{category:0, display:'Admissibilité à vérifier', template:'{{Admissibilité à vérifier|date=$(month) $(year)|motif=$(reason)}}', reason:'Motif :', help:''},
	{category:3, display:'Alerte langue', template:'{{Alerte langue|$(reason)|$(extra)}}', extra:'Nom de la langue, tel qu’utilisé dans l’article relatif à cette langue :', reason:'nom de la langue utilisée ainsi qu’au moins une lettre de cette langue qui pourrait poser des problèmes d’affichage :', help:''},
	{category:2, display:'Anecdotes', template:'{{Anecdotes}}', help:''},
	{category:2, display:'Anthropocentrisme', template:'{{Anthropocentrisme|date=$(month) $(year)}}', help:''},
	{category:3, display:'Article court', template:'{{Article court|$(extra)}}', extra:'Article dans lequel le sujet est plus développé :', help:''},
	{category:0, display:'Article en sursis', template:'{{Article en sursis|timestamp={{subst:' + 'CURRENTTIMESTAMP}}}}', help:''},
	{category:0, display:'Article incompréhensible', template:'{{Article incompréhensible|date=$(month) $(year)}}', help:''},
	{category:3, display:'Article mal proportionné', template:'{{Article mal proportionné}}', help:''},
	{category:2, display:'Article non neutre', template:'{{Article non neutre|date=$(month) $(year)}}', help:''},
	{category:3, display:'Av. J.-C.', template:'{{Av. J.-C.}}', help:''},
	{category:0, display:'Avantage non déclaré', template:'{{Avantage non déclaré|date=$(month) $(year)|motif=$(reason)}}', reason:'Motif :', help:''},
	{category:3, display:'Avertissement liste wikidata', template:'{{Avertissement liste wikidata}}', help:''},
	{category:3, display:'Confusion', template:'{{Confusion|$(reason)}}', reason:'Lien(s) vers un ou plusieurs autres articles, séparés par des « | » :', help:''},
	{category:4, display:'Conventions bibliographiques', template:'{{Conventions bibliographiques|date=$(month) $(year)}}', help:''},
	{category:0, display:'Copie à vérifier', template:'{{Copie à vérifier|1=$(reason)|date=$(month) $(year)}}', reason:'Adresse du site copié :', help:''},
	{category:2, display:'Désaccord de neutralité', template:'{{Désaccord de neutralité|date=$(month) $(year)}}', help:''},
	{category:2, display:'Désaccord de pertinence', template:'{{Désaccord de pertinence|date=$(month) $(year)}}', help:''},
	{category:4, display:'Détournement de sources', template:'{{Détournement de sources}}', help:''},
	{category:0, display:'En travaux', template:'{{En travaux|$(user)|date=$(day) $(month) $(year)|commentaire=$(extra)}}', extra:'Commentaire facultatif :', help:''},
	{category:3, display:'Fusion technique', template:'{{Fusion technique|$(extra)}}', extra:'Liste des articles qui font l\'objet de la fusion, sparés par des « | » :', help:''},
	{category:0, display:'Internationaliser', template:'{{Internationaliser|date=$(month) $(year)}}', help:''},
	{category:2, display:'Introduction régionale', template:'{{Introduction régionale|date=$(month) $(year)}}', help:''},
	{category:4, display:'Lien internet incomplet', template:'{{Lien internet incomplet}}', help:''},
	{category:3, display:'Lire d\'abord', template:'{{Lire d\'abord|$(extra)}}', extra:'Liste des articles à lire d\'abord, séparés par des « | » :', reason:'', help:''},
	{category:0, display:'Mettre à jour', template:'{{Mettre à jour|$(reason)|date=$(month) $(year)|commentaire=$(extra)}}', extra:'Justification de la présence du bandeau (facultatif) :', reason:'Date de dernière mise à jour (facultatif) :', help:''},
	{category:1, display:'Notoriété art', template:'{{Notoriété art|date=$(month) $(year)}}', help:''},
	{category:0, display:'Orthographe', template:'{{Orthographe|date=$(month) $(year)}}', help:''},
	{category:4, display:'Pas de liens externes', template:'{{Pas de liens externes}}', help:''},
	{category:3, display:'Plan', template:'{{Plan|date=$(month) $(year)}}', help:''},
	{category:3, display:'Plusieurs en cours', template:'{{Plusieurs en cours}}', help:''},
	{category:2, display:'Point de vue interne', template:'{{Point de vue interne|date=$(month) $(year)}}', help:''},
	{category:1, display:'Pour Wikiquote', template:'{{Pour Wikiquote}}', help:''},
	{category:2, display:'POV fork', template:'{{POV fork}}', help:''},
	{category:0, display:'Promotionnel', template:'{{Promotionnel|date=$(month) $(year)}}', help:''},
	{category:0, display:'R3R', template:'{{R3R|1=~~~~}}', help:''},
	{category:3, display:'Redirect confusion', template:'{{Redirect confusion|$(reason)|$(extra)}}', extra:'Confusion possible avec l\'article :', reason:'Nom de la redirection :', help:''},
	{category:3, display:'Résumé introductif', template:'{{Résumé introductif|date=$(month) $(year)}}', help:''},
	{category:3, display:'Résumé introductif trop court', template:'{{Résumé introductif trop court|date=$(month) $(year)}}', help:''},
	{category:3, display:'Résumé introductif trop long', template:'{{Résumé introductif trop long|date=$(month) $(year)}}', help:''},
	{category:4, display:'Sans source', template:'{{Sans source|date=$(month) $(year)}}', help:''},
	{category:2, display:'Scrutin en cours', template:'{{Scrutin en cours}}', help:''},
	{category:4, display:'Sources à lier', template:'{{Sources à lier|date=$(month) $(year)}}', help:''},
	{category:4, display:'Sources obsolètes', template:'{{Sources obsolètes|date=$(month) $(year)}}', help:''},
	{category:0, display:'Sources secondaires', template:'{{Sources secondaires|date=$(month) $(year)}}', help:''},
	{category:0, display:'Style non encyclopédique', template:'{{Style non encyclopédique|date=$(month) $(year)}}', help:''},
	{category:3, display:'Synopsis', template:'{{Synopsis|date=$(month) $(year)}}', help:''},
	{category:3, display:'Titre incorrect', template:'{{Titre incorrect|1=$(reason)}}', reason:'Titre souhaité :', help:''},
	{category:0, display:'Travail inédit', template:'{{Travail inédit|date=$(month) $(year)|Cet article peut contenir}}', help:''},
	{category:3, display:'Trop d\'images', template:'{{Trop d\'images|date=$(month) $(year)}}', help:''},
	{category:3, display:'Trop de citations', template:'{{Trop de citations|date=$(month) $(year)}}', help:''},
	{category:3, display:'Trop de liens', template:'{{Trop de liens|date=$(month) $(year)}}', help:''},
	{category:3, display:'Trop de wikiliens', template:'{{Trop de wikiliens|date=$(month) $(year)}}', help:''},
	{category:3, display:'Trop long', template:'{{Trop long}}', help:''},
	{category:0, display:'Typographie', template:'{{Typographie|date=$(month) $(year)}}', help:''},
	{category:1, display:'Vérifiabilité', template:'{{Vérifiabilité|date=$(month) $(year)}}', help:''},
	{category:1, display:'Vie privée', template:'{{Vie privée|date=$(month) $(year)}}', help:''},
  ],
  categories_container: null,
  alphabetic_container: null,
  current_display_mode: "categories",

  init: function() {
  },
  launch: function() {
  	if(mw.config.get('wgArticleId') === 0) {
    	mw.notify(C.tag.config['notify-not-a-page'], {title:'C-helper', type:'error'});
    	return;
  	}
  	if(mw.config.get('wgRestrictionEdit') == ["sysop"]) {
    	mw.notify(C.tag.config['notify-protected'], {title:'C-helper', type:'error'});
    	return;
  	}
	if(this.dialog === null) {
		this.build_dialog();
	}
	this.dialog.dialog("open");
  },
  "build_dialog": function() {
    this.dialog = $('<div>', {title:this.config['modal-title']});
    var form = $('<form>');
    this.dialog.append(form);
    //Radio
    $("<div>").text("Trier par ")
               .append($("<input>", {type:"radio",name:"C-tag-display-mode", value:"categories", id:"C-tag-display-mode-categories", class:this.config['c-tag-radio-class'], checked: "checked"}))
               .append($("<label>", {"for":"C-tag-display-mode-categories"}).text("Catégories"))
               .append($("<input>", {type:"radio",name:"C-tag-display-mode", value:"alphabetic", id:"C-tag-display-mode-alphabetic", class:this.config['c-tag-radio-class']}))
               .append($("<label>", {"for":"C-tag-display-mode-alphabetic"}).text("Ordre alphabétique"))
               .appendTo(form);

    //Create sections
    this.alphabetic_container = $("<div>", {id:"C-tag-alphabetic-container"});
    this.categories_container = $("<div>", {id:"C-tag-categories-container"});
    for(var i=0; i<this.categories.length; i++) {
    	this.categories[i].node = $("<div>").append($("<h3>").text(this.categories[i].display)).appendTo(this.categories_container);
    }
    for(var i=0; i<this.templates.length; i++) {
		this.templates[i].node = $("<div>");
		this.templates[i].node.append($("<input>", {type:"checkbox", id:"C-tag-"+i, tag_id:i, class:this.config['c-tag-checkbox-class']}));
		this.templates[i].node.append($("<label>", {"for":"C-tag-"+i}).text(this.templates[i].display));
		
		if(this.templates[i].help !== '') {
			this.templates[i].node.append(C.util.construct_help_icon(this.templates[i].help));
		}
		if(this.templates[i].hasOwnProperty('reason')) {
			this.templates[i].node.append($('<span>', {id:'C-tag-reason-'+i, class:this.config['c-tag-reason-class']})
			                      		.hide()
			                      		.append($('<br>'))
			                            .append($('<label>', {"for":'C-tag-reason-input-'+i}).html(this.templates[i].reason))
			                            .append("&nbsp;")
			    						.append($('<input>', {type:'text', id:'C-tag-reason-input-'+i})));
		}
		if(this.templates[i].hasOwnProperty('extra')) {
			this.templates[i].node.append($('<span>', {id:'C-tag-extra-'+i, class:this.config['c-tag-extra-class']})
			                      		.hide()
			                      		.append($('<br>'))
			                            .append($('<label>', {"for":'C-tag-extra-input'+i}).html(this.templates[i].extra))
			                            .append("&nbsp;")
			    						.append($('<input>', {type:'text', id:'C-tag-extra-input'+i})));
		}
		
		this.categories[this.templates[i].category].node.append(this.templates[i].node);
    }
    form.append(this.alphabetic_container);
    form.append(this.categories_container);
    
    this.dialog.dialog({
      autoOpen: false,
      height: 400,
      width: 600,
      modal: true,
      buttons: [
        {
          text: C.tag.config['submit'],
          click: function() {
            C.tag.dialog.dialog("close");
            C.tag.validate();
          },
        },
      ],
    dialogClass: 'c-helper-dialog',
    });
    $('.'+this.config['c-tag-radio-class']).change(function() {
    	C.tag.switch_display_mode($(this).val());
    });
	$('.'+this.config['c-tag-checkbox-class']).change(function() {
		if($(this).is(":checked")) {
			$('#C-tag-reason-'+$(this).attr('tag_id')).show();
			$('#C-tag-extra-'+$(this).attr('tag_id')).show();
		}
		else {
			$('#C-tag-reason-'+$(this).attr('tag_id')).hide();
			$('#C-tag-extra-'+$(this).attr('tag_id')).hide();
		}
	});
  },
  switch_display_mode: function(new_mode) {
  	if(this.current_display_mode != new_mode) {
  		if(new_mode == "categories") {
  			$("#C-tag-categories-container").show();
  			for(var i=0; i<this.templates.length; i++) {
				this.categories[this.templates[i].category].node.append(this.templates[i].node);
			}
			$("#C-tag-alphabetic-container").hide();
  		}
  		else {
			$("#C-tag-alphabetic-container").show();
  			for(var i=0; i<this.templates.length; i++) {
				this.alphabetic_container.append(this.templates[i].node);
			}
  			$("#C-tag-categories-container").hide();
  		}
  		this.current_display_mode = new_mode;
  	}
  },
  validate: function() {
  	var to_prepend = "";
  	var summary_array = [];
  	for(var i=0; i<this.templates.length; i++) {
  		if($('#C-tag-'+i).is(':checked')) {
  			var tmp = this.templates[i].template.replace(/\$\(day\)/g, "{{subst:CURRENTDAY}}")
  			                             .replace(/\$\(month\)/g, "{{subst:CURRENTMONTHNAME}}")
  			                             .replace(/\$\(year\)/g, "{{subst:CURRENTYEAR}}")
  			                             .replace(/\$\(page\)/g, mw.config.get('wgPageName'))
  			                             .replace(/\$\(diff\)/g, mw.config.get('wgRevisionId'))
  			                             .replace(/\$\(user\)/g, mw.config.get('wgUserName'));
  			if($('#C-tag-reason-input-'+i).length > 0) {
  				tmp = tmp.replace(/\$\(reason\)/g, $('#C-tag-reason-input-'+i).val());
  			}
  			if($('#C-tag-extra-input'+i).length > 0)
  				tmp = tmp.replace(/\$\(extra\)/g, $('#C-tag-extra-input'+i).val());
  				
  			to_prepend += tmp+'\n';
  			summary_array.push(this.templates[i].display);
  		}
  	}
  	if(summary_array.length > 0) {
  		var template_links = summary_array.map(function(item) {
  			return this.config['template-link-summary'].replace(/\$1/g, item);
  		}, this);
  		var summary = this.config['add-summary'].replace(/\$1/g, C.util.array_to_text(template_links));
  		C.util.prepend(null, to_prepend, summary, function() {
  			mw.notify(C.tag.config['notify-success'], {title:'C-helper', type:'info'});
	    	C.util.reload();
  		});
  	}
  },
};

C.modules.tag.callback = C.tag;
//</nowiki>